package com.todo.client.gui.dialog.user.login;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.google.gwt.user.client.ui.RootPanel;
import com.todo.client.gui.dialog.AbstractDialog;
import com.todo.client.gui.dialog.user.account.AccountDialog;
import com.todo.client.gui.window.main.MainWindow;

public class LoginDialog extends AbstractDialog{
			
	private TextField<String> login;
	private TextField<String> password;
	
	public LoginDialog() {
		super();
		getDialog(MESSAGES.loginTitle());
        
        login = getTextField(MESSAGES.login());
        password = getTextField(MESSAGES.password());
        
        add(login);
        add(password);
	}
	
	
	@Override
	protected void createButtons() {
		super.createButtons();
		getButtonBar().add(new FillToolItem());
        
		Button reset = getButton(MESSAGES.reset());
		reset.addSelectionListener(new SelectionListener<ButtonEvent>() {
			
			@Override
			public void componentSelected(ButtonEvent ce) {
				// TODO Auto-generated method stub
				
			}
		});
		
		Button signin = getButton(MESSAGES.signin());
		signin.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				LoginDialog.this.hide();
				RootPanel.get().add(new MainWindow());
				
			}
		});
		
		Button signup = getButton(MESSAGES.signup());
		signup.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				new AccountDialog().show();
				
			}
		});
		
		addButton(reset);
        addButton(signin);        
        addButton(signup);
	}
	
	@Override
	protected void validate() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected boolean hasValue() {
		// TODO Auto-generated method stub
		return false;
	}	
}
